package cn.study.hashMapTest;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ：大佳
 * @description :HashMap存在数据丢失示例
 */
public class HashMapDataLost {
    public static final Map<String, String> map = new HashMap<String, String>();

    public static void main(String[] args) throws InterruptedException {
        //线程一
        Thread thread1 = new Thread() {
            public void run() {
                for (int i = 0; i < 1000; i++) {
                    map.put(String.valueOf(i), String.valueOf(i));
                }
            }
        };
        //线程二
        Thread thread2 = new Thread() {
            public void run() {
                for (int j = 1000; j < 2000; j++) {
                    map.put(String.valueOf(j), String.valueOf(j));
                }
            }
        };

        thread1.start();
        thread2.start();

        // 等待两个线程执行完毕
        thread1.join();
        thread2.join();

        //输出
        System.out.println("Final size of map: " + map.size());
    }

}
